//
//  RankListCell.m
//  ShrimpCrowdordering
//
//  Created by 郑洲 on 2018/7/25.
//  Copyright © 2018年 郑洲. All rights reserved.
//

#import "RankListCell.h"

@interface RankListCell ()

@property (nonatomic, strong) UIImageView *headView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *numLabel;
@property (nonatomic, strong) UILabel *numberLabel;
@property (nonatomic, strong) UIButton *concernBtn;

@end

@implementation RankListCell

+ (RankListCell *)cellWithTableView:(UITableView *)tableView andIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"RankListCell";
    RankListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[RankListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.backgroundColor = TABLEVIEW_BACKGROUNDCOLOR;
        [cell createSubView];
    }
    
    return cell;
}

- (void)createSubView {
    self.headView = [[UIImageView alloc] initWithFrame:CGRectMake(ScreenX375(46), ScreenX375(16), ScreenX375(65), ScreenX375(65))];
    self.headView.image = ImageWithName(@"头像1");
    [self addSubview:self.headView];
    
    self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(121), ScreenX375(23), ScreenX375(150), ScreenX375(18))];
    self.nameLabel.textColor = FONTCOLOR_BLACK;
    self.nameLabel.font = Kfont(16);
    self.nameLabel.text = @"南有佳人";
    [self addSubview:self.nameLabel];
    
    self.numLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(121), ScreenX375(54), ScreenX375(150), ScreenX375(16))];
    self.numLabel.textColor = REXADECIMALCOLOR(@"#9b9b9b");
    self.numLabel.font = Kfont(14);
    self.numLabel.text = @"粉丝数：4200";
    [self addSubview:self.numLabel];
    
    self.numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(40), ScreenX375(25), ScreenX375(16))];
    self.numberLabel.textColor = REXADECIMALCOLOR(@"#f5a623");
    self.numberLabel.font = Kfont(16);
    self.numberLabel.text = @"02";
    [self addSubview:self.numberLabel];
    
    self.concernBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - ScreenX375(80), ScreenX375(36), ScreenX375(64), ScreenX375(26))];
    [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
    self.concernBtn.titleLabel.font = Kfont(14);
    [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
    self.concernBtn.layer.cornerRadius = ScreenX375(13);
    self.concernBtn.layer.borderWidth = 1;
    self.concernBtn.layer.borderColor = REXADECIMALCOLOR(@"#eaeaea").CGColor;
    [self.concernBtn addTarget:self action:@selector(concern) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:self.concernBtn];
    
    UIView *line = [[UIView alloc] initWithFrame:CGRectMake(ScreenX375(16), ScreenX375(99) - 0.5, SCREEN_WIDTH - ScreenX375(32), 0.5)];
    line.backgroundColor = LineColor;
    [self addSubview:line];
}

- (void)concern {
    if (_concernClick) {
        _concernClick();
    }
}

- (void)setRankModel:(RankModel *)rankModel {
    _rankModel = rankModel;
    
    self.nameLabel.text = _rankModel.nickName;
    if ([_rankModel.pic class] != [NSNull class]) {
        [self.headView sd_setImageWithURL:[NSURL URLWithString:_rankModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    }
    self.headView.clipsToBounds = YES;
    self.headView.layer.cornerRadius = ScreenX375(32.5);
    self.numLabel.text = [NSString stringWithFormat:@"粉丝数:%@",_rankModel.fensNum];
    self.numberLabel.text = [NSString stringWithFormat:@"%02ld",(long)[_rankModel.no integerValue]];
    if ([_rankModel.isFollow integerValue]) {
        [self.concernBtn setTitle:@"已关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#212121") forState:UIControlStateNormal];
        [self.concernBtn setImage:nil forState:UIControlStateNormal];
    }else {
        [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
        [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    }
}

- (void)setChannelRankModel:(ChannelRankModel *)channelRankModel {
    _channelRankModel = channelRankModel;
    
    self.nameLabel.text = _channelRankModel.channelName;
    [self.headView sd_setImageWithURL:[NSURL URLWithString:_channelRankModel.pic] placeholderImage:nil options:SDWebImageRetryFailed];
    self.numLabel.text = [NSString stringWithFormat:@"粉丝数:%@",_channelRankModel.fensNum];
    self.numberLabel.text = [NSString stringWithFormat:@"%02ld",(long)[_channelRankModel.no integerValue]];
    if ([_channelRankModel.isFollow integerValue]) {
        [self.concernBtn setTitle:@"已关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#212121") forState:UIControlStateNormal];
        [self.concernBtn setImage:nil forState:UIControlStateNormal];
    }else {
        [self.concernBtn setTitle:@" 关注" forState:UIControlStateNormal];
        [self.concernBtn setTitleColor:REXADECIMALCOLOR(@"#ff2469") forState:UIControlStateNormal];
        [self.concernBtn setImage:ImageWithName(@"添加关注") forState:UIControlStateNormal];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

@implementation RankModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end

@implementation ChannelRankModel

+(JSONKeyMapper*)keyMapper
{
    return [[JSONKeyMapper alloc] initWithModelToJSONDictionary:@{
                                                                  @"Id": @"id"
                                                                  }];
}


@end
